/***************************************************************************
 *   Copyright (C) 2007 by Ivan Topolsky   *
 *   ivan.topolsky@genebio.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <fstream>
#include <boost/archive/xml_oarchive.hpp>

#include "utils/runlcmsmsreadermgf.h"

using namespace std;
using namespace bol;

#define STRINGIFY(x) XSTRINGIFY(x)
#define XSTRINGIFY(x) #x

void printNearPrecursor(const double mass);
static RunLcmsms run;

int main(int argc, char **argv){
  string file;
  if(argc>1){
    file=string(argv[1]);
  }else{
    file=STRINGIFY(DATADIR) "/a.mgf";
  }
  

  RunLcmsmsReaderMGF reader;
  reader.read(run, file);

  for(int i=0; i<run.msmsCollection().size(); i++){
    cout<<run.msmsCollection()[i]<<endl;
  }

#ifdef HAVE_BOOST_SERIALIZATION
  // save data to archive
  {
    ofstream ofs("/tmp/testser.xml");
    boost::archive::xml_oarchive oa(ofs);
    // if your program traps here, it indicates taht your doing one of the following:
    // a) serializing an object of a type marked "track_never" through a pointer.
    // b) saving an non-const object of a type not markd "track_never)
    // Either of these conditions may be an indicator of an error usage of the
    // serialization library and should be double checked.  See documentation on
    // object tracking.
    oa << BOOST_SERIALIZATION_NVP(run);
  }
#else
    cerr << "boost serialisation isn't compiled in" << endl;
#endif

  cerr << "boost de-serialisation isn't currently functionnal" << endl;
  // FIXME currently boost de-serialisation  doesn't work
  // TODO lots of "const" have to be replaced with "mutable" and default constructors are needed

  return 0;
}
